<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-product-add">
			<h4>添加产品信息</h4>
			<br>
			<hr>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>产品名称：</label>
						<div class="col-sm-8">
							<input class="form-control" placeholder="请输入产品名称" type="text" name="productName" id="productName" required>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属平台：</label>
						<div class="col-sm-8">
							<select class="form-control m-b" id="productDeptId" name="productDeptId" required placeholder="请选择赠品" onchange="selectDept()">
								<option value="">请选择归属平台</option>
							</select>
						</div>
					</div>
				</div>


			</div>
			<div class="row">
				<div class="col-sm-6">
				<div class="form-group">
				<label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属店铺：</label>
				<div class="col-sm-8">
				<select class="form-control m-b" id="productShopId" name="productShopId" required >
				<option value="">请选择归属店铺</option>
				</select>
				</div>
				</div>
				</div>

				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>赠品：</label>
						<div class="col-sm-8">
							<select class="form-control m-b" id="productGiftId" name="productGiftId" required placeholder="请选择赠品">
								<option value="">请选择赠品</option>
							</select>
						</div>
					</div>
				</div>
			</div>
			<!--<br>-->
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>成本：</label>
						<div class="col-sm-8">
							<input class="form-control" placeholder="请输入成本" type="number" name="productCost" id="productCost" required>
						</div>
					</div>
				</div>

			</div>
			<hr>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script type="text/javascript">
		var prefix = ctx + "product/product";


        $(function () {
            getAllDept()
            getAllGift()

        })
		
		
		// 获取所有的平台信息
		function getAllDept() {
            $.ajax({
                type: "GET",
                url: prefix +'/allDept',
                async: false,
                contentType : 'application/json;charset=utf-8',
                traditional:true,
                success : function(data) {
                    for(var i=0;i<data.length;i++){
                        var html = "<option value='"+data[i].deptId+"'>"+data[i].deptName + "</opinion>"
                        $("#productDeptId").append(html);
                    }
                },
                error:function(e) {
                    console.info(e);
                }
            });
        }

        //根据选择的平台获取店铺
		function selectDept() {

            $.ajax({
                type: "POST",
                url: prefix +'/selectByDeptId?id='+$("#productDeptId").val(),
                async: false,
                contentType : 'application/json;charset=utf-8',
                traditional:true,
                success : function(data) {
                    var html="<option value=''>请选择归属店铺</opinion>";;
                    for(var i=0;i<data.length;i++){
                        html+="<option value='"+data[i].id+"'>"+data[i].shopName + "</opinion>";

					}
                    $("#productShopId").empty().append(html);
                },
                error:function(e) {
                    console.info(e);
                }
            });
        }

		// 获取所有的赠品信息
		function getAllGift() {
            // 查询所有的赠品
            $.ajax({
                type: "GET",
                url: prefix +'/allGift',
                async: false,
                contentType : 'application/json;charset=utf-8',
                traditional:true,
                success : function(data) {
                    for(var i=0;i<data.length;i++){
                        var html = "<option value='"+data[i].id+"'>"+data[i].giftName + "</opinion>"
                        $("#productGiftId").append(html);
                    }
                },
                error:function(e) {
                    console.info(e);
                }
            });

        }
		
		


		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/saveProduct", $('#form-product-add').serialize());
	        }
	    }

        






	    
	</script>
</body>
</html>
